package org.javaboy.system_task;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

@Component
public class MyApplicationRunner01 implements ApplicationRunner, Ordered {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        //获取所有的参数，无论是 key-value 格式还是非 key-value 格式
        String[] sourceArgs = args.getSourceArgs();
        System.out.println("Arrays.toString(sourceArgs) = " + Arrays.toString(sourceArgs));
        Set<String> optionNames = args.getOptionNames();
        for (String optionName : optionNames) {
            System.out.println(optionName + ">>>" + args.getOptionValues(optionName));
        }
        List<String> nonOptionArgs = args.getNonOptionArgs();
        System.out.println("nonOptionArgs = " + nonOptionArgs);
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
